package cmcciot.onenet.nbapi.sdk.entity;

import cmcciot.onenet.nbapi.sdk.config.Config;

import java.time.LocalDateTime;

/**
 * @author LHL
 * @date: 2018/8/1
 */
public class ReadDeviceCommandList extends CommonEntity {
    //指定开始时间,必选
    private LocalDateTime start;
    //指定结束时间,可选
    private LocalDateTime end;
    //指定结束时间,可选
    private Integer page;
    //每一页多少条
    private Integer perPage;
    //时间排序方式，DESC:降序，ASC升序，默认降序
    private String sort;


    public ReadDeviceCommandList(String imei, LocalDateTime start) {
        this.imei = imei;
        this.start = start;
    }

    public LocalDateTime getEnd() {
        return end;
    }

    public void setEnd(LocalDateTime end) {
        this.end = end;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getPerPage() {
        return perPage;
    }

    public void setPerPage(Integer perPage) {
        this.perPage = perPage;
    }

    public String getSort() {
        return sort;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    @Override
    public String toUrl() {
        StringBuilder url = new StringBuilder(Config.getDomainName());
        url.append("/nbiot/offline/history?imei=").append(this.imei);
        url.append("&start=").append(this.start.withNano(0).toString());
        if (this.end != null) {
            url.append("&end=").append(this.end.withNano(0).toString());
        }
        url.append("&page=").append(this.page == null ? 12 : this.page);
        url.append("&per_page=").append(this.perPage == null ? 10 : this.perPage);
        url.append("&sort=").append(this.sort == null ? "DESC" : this.sort);
        return url.toString();
    }
}
